package com.example.shirospringboot.config;

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetTransactionStatement;
import com.example.shirospringboot.pojo.Client;
import com.example.shirospringboot.service.customService.CustomService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.servlet.http.HttpSession;

public class CustomRealm extends AuthorizingRealm {

    @Autowired
    CustomService customService;

    //授权
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    //认证
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {

        UsernamePasswordToken userToken=(UsernamePasswordToken)authenticationToken;

        Client client = customService.queryClient(userToken.getUsername());

        if(client==null){//没有此人
            return null;
        }




        //密码认证shiro做
        return new SimpleAuthenticationInfo(client,client.getCustomPwd(),"");
    }
}
